import BaseAd from "../../core/base/BaseAd";
import { registerClass } from "../../../cfw/tools/class_decorator";
import { ResultState, SDKState } from "../../SDKDefine";


@registerClass('GDRewardAd')
export class GDRewardAd extends BaseAd {

    open() {
        if (window['gdsdk'] !== 'undefined' && window['gdsdk']['showAd']) {
            this.setState(SDKState.show)
            window['gdsdk'].showAd('rewarded');
        } else {
            this.onErrorLogic()
        }
    }

    onErrorLogic() {
        this.callResultCallback(ResultState.NO)
    }


    onClose(res: any) {
        console.log('GDRewardAd onClose ', res)
        this.setState(SDKState.close)
        if (res && res.isEnded || res === undefined) {
            this.callResultCallback(ResultState.YES)
        } else {
            this.callResultCallback(ResultState.NO)
        }
    }
}